﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;

namespace XCommunity.Users
{

  /// <summary>
  /// IControlConstraint的一个标准实现
  /// </summary>
  public class ControlConstraint : IControlConstraint
  {

    public ControlConstraint( ControlConstraintDelegate constraintMethod )
    {
      _constraintMethod = constraintMethod;
    }

    private ControlConstraintDelegate _constraintMethod;


    #region IControlConstraint 成员

    /// <summary>
    /// 检查是否满足权限条件
    /// </summary>
    /// <param name="user">当前用户</param>
    /// <param name="verb">当前动作</param>
    /// <param name="frameObjects">涉及到的框架对象</param>
    /// <returns></returns>
    public bool IsSatisfied( IPrincipal user, string verb, params object[] frameObjects )
    {
      return _constraintMethod( user, verb, frameObjects );
    }

    #endregion
  }

  /// <summary>
  /// 定义查询权限控制项约束的方法签名
  /// </summary>
  /// <param name="user">当前用户</param>
  /// <param name="verb">当前动作</param>
  /// <param name="frameObjects">涉及到的框架对象</param>
  /// <returns></returns>
  public delegate bool ControlConstraintDelegate( IPrincipal user, string verb, object[] frameObjects );
}
